package com.qiankan.qmsj.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;

import com.umeng.analytics.MobclickAgent;
import com.qiankan.qmsj.R;
import com.qiankan.qmsj.utils.StatusBarUtil;
import com.qiankan.qmsj.widget.LoadDialog;

import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/8/14.
 */

public abstract class BaseActivity extends Activity {
    private static final String TAG = "BaseActivity";
    private LoadDialog mLoadInstance;

    public abstract int getContentViewId();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getContentViewId());
        ButterKnife.bind(this);
        mLoadInstance = new LoadDialog(this);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//禁止横屏
        StatusBarUtil.setStatusBarColor(this, R.color.transparent);
        StatusBarUtil.statusBarLightMode(this);
        initAllMembersView(savedInstanceState);
        // runtime permission for android 6.0, just require all permissions here for simple
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);//友盟统计
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    protected abstract void initAllMembersView(Bundle savedInstanceState);

    protected void startActivity(Context context, Class<? extends Activity> targetActivity) {
        startActivity(new Intent(context, targetActivity));
        overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);
    }

    public void showLoadingDialog() {
        if (mLoadInstance == null) {
            mLoadInstance = new LoadDialog(this);
        }
        mLoadInstance.show();
    }

    public void dismissLoadingDialog() {
        if (mLoadInstance != null) {
            Log.d(TAG, "dismissLoadingDialog: " + mLoadInstance.isShowing());
            if (mLoadInstance.isShowing()) {
                try {
                    mLoadInstance.dismiss();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
